#a安装
# pip  install  bs4

import requests
from  bs4 import BeautifulSoup


#获取数据
url = "https://movie.douban.com/top250"
headers = {
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0"
}
response = requests.get(url,headers=headers)
page_content = response.text

#解析数据
#1.把页面源代码交给BeautifulSoup进行处理, 返回bs对象
page = BeautifulSoup(page_content,'html.parser') #指定html解析器
#2.从bs对象中查找数据
#find(标签,属性=值) 找第一个
#find_all(标签,属性=值) 找出全部
# ol = page.find("ol",class_="grid_view")#class是Python的关键字
ol = page.find("ol",attrs={"class":"grid_view"})#和尚一行是一个意思  可以避免关键词的使用

lis = ol.find_all("li")[1:]
for li in lis:
    ps = li.find_all("p")
    intro  = ps[0].text.strip()
    quote = ps[1].text.strip()
    print(intro,"\n",quote)

response.close()
